package com.yunhe.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.yunhe.entity.Goods;
import com.yunhe.entity.Orders;
import com.yunhe.entity.User;
import com.yunhe.util.MyBatisUtil;

public class OrdersImpl implements IOrders {

	SqlSession ss = MyBatisUtil.getSession();
	@Override
	public int addOrder(Goods goods, User user,int number,String address,String remark){
		Map map = new HashMap();
		map.put("gname", goods.getGname());
		map.put("price",goods.getPrice());
		map.put("number", number);
		map.put("total", number*goods.getPrice());
		map.put("address", address);
		map.put("remark", remark);
		map.put("username", user.getUsername());
		int count = ss.insert("com.yunhe.dao.IOrders.addOrder", map);
		ss.commit();
		ss.close();
		return count;
	}
	@Override
	public int updateOrders(Orders orders,int price, int number,String address, String remark, int state){
		Map map = new HashMap();
		map.put("oid", orders.getOid());
		map.put("price",price);
		map.put("number", number);
		map.put("total", number*price);
		map.put("address", address);
		map.put("remark", remark);
		map.put("state", state);
		int count = ss.update("com.yunhe.dao.IOrders.updateOrders", map);
		ss.commit();
		ss.close();
		return count;
	}
	@Override
	public int delOrders(Orders orders) {
		int count = ss.delete("com.yunhe.dao.IOrders.delOrders", orders);
		ss.commit();
		ss.close();
		return count;
	}
	@Override
	public List<Map> getAllOrders() {
		List<Map> map = ss.selectList("com.yunhe.dao.IOrders.getAllOrders");
		ss.close();
		return map;
	}

}
